<?php
	/**
	 * 一键删除邮件
	 */
    class OneKeyDel extends APIBase {
		
		public $tag = "OneKeyDel";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic() {
			//获取用户信息
			$uid = $this->uid;
			//$userinfo = $this->data_redis->hmGet("hu:{$uid}",array("room_card","room_card_coop","coin"));
			
			//获取邮件列表
			$hUserEmailList = $this->cache_redis->keys("hUserEmailList:$uid:*");

			$count = count($hUserEmailList);
			if ($count) {
				$msg = array();
				$time = time();
				for($i=0;$i<$count;$i++){				  
				    $list = $this->cache_redis->hGetAll("hUserEmailList:$uid:".$i);            
                        if($list['rewardid']!=0 && $list['receivestatus']==0){
							$msg[] = $list['id'];
						}elseif($list['rewardid']!=0 && $list['receivestatus']!=0){
                            //$this->mysql->query("update mail_send set is_read = 9,update_date=$time where uid = $uid and id = ".$list['id']);
                            $this->cache_redis->hMset("hUserEmailList:$uid:".$i, array('readstatus'=>9));								
						}elseif($list['rewardid']==0){
							//$this->mysql->query("update mail_send set is_read = 9,update_date=$time where uid = $uid and id = ".$list['id']);
							$this->cache_redis->hMset("hUserEmailList:$uid:".$i, array('readstatus'=>9));
						}												  
				}
				if(!empty($msg)){
					$this->returnError(301,"部分邮件的附件未领取,请领取了附件再删除邮件");
				}else{
					$this->returnData(0);
				}

			}else{
				$this->returnError(302,"尚未可删除的邮件！");
			}
		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
